package internetplus_test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
/**
 *
 * @author luobo
 */
public class ForumTest {

    public static void main(String args[]) throws IOException {
        register();
//        login();
//        exitLogin();
    }

    public static void loadTopics(){
        String httpUrl="http://localhost:8080/InternetPlus/forum/loadTopics";

//        String httpUrl="http://118.89.29.87:8080/InternetPlus/forum/loadTopics";
        InternetRequest.request_getWithoutCookie(httpUrl);
    }
          
    public static void login() throws IOException {
//        String httpUrl = "http://localhost:8080/InternetPlus/authorization/login";
        String httpUrl = "http://118.89.29.87:8080/InternetPlus/authorization/login";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("email", "758172047@qq.com");
        jsonObject.put("password", "1234567890");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithoutCookie(httpUrl, params);
    }
    
    public static void register(){
        String httpUrl = "http://localhost:8080/InternetPlus/register";
//        String httpUrl = "http://118.89.29.87:8080/InternetPlus/register";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("email", "123456789@qq.com");
        jsonObject.put("password", "1234567890");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithoutCookie(httpUrl, params);
    }

    public static void testAddNewTopic() throws IOException {
//        String httpUrl = "http://118.89.29.87:8080/InternetPlus/forum/addNewTopic";

        String httpUrl = "http://localhost:8080/InternetPlus/forum/addNewTopic";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("content", "This is a test!");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);
    }
    
    public static void testDeleteTopic(){
        String httpUrl = "http://localhost:8080/InternetPlus/forum/deleteTopic1";
        List<NameValuePair> params = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("tid", 1);
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);
    }
    
    public static void testAddNewReply(){
//        String httpUrl = "http://118.89.29.87:8080/InternetPlus/forum/addNewReply";

        String httpUrl = "http://localhost:8080/InternetPlus/forum/addNewReply";
        List<NameValuePair> params = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("tid", 2);
        jsonObject.put("content", "This is a test!");
        jsonObject.put("toW", 1);
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);
    }
    
    public static void testDeleteReply(){
        String httpUrl = "http://localhost:8080/InternetPlus/forum/deleteReply";
        List<NameValuePair> params = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("rid", 3);
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);
    }  
    
    public static void exitLogin(){
//        String httpUrl="http://localhost:8080/InternetPlus/authorization/exitLogin";
        String httpUrl = "http://118.89.29.87:8080/InternetPlus/authorization/exitLogin";
        InternetRequest.request_getWithCookie(httpUrl);
    }
}
